<?php
class kriteria extends MY_Controller{
    function kriteria(){
        parent::MY_Controller();
        $this->data['title'] = 'Master Data Kriteria';
        $this->load->model('m_kriteria');
    }
    
    var $data;
    var $limit = 10;
    
    function index(){
        $this->get_kriteria();
    }
    function get_kriteria($offset = 0){
        $this->data['content'] = 'kriteria/v_kriteria';
        
        $uri_segment = 3;
        if($offset != 0){
          $offset = $this->uri->segment($uri_segment);  
        }
        $num_rows = $this->m_kriteria->getCountRows();
        $this->data['listKriteria'] = $this->m_kriteria->getListKriteria($offset,$this->limit);
        $config['base_url'] = site_url('kriteria/get_kriteria');
        $config['total_rows'] = $num_rows;
        $config['per_page'] = $this->limit;
        $config['uri_segment'] = $uri_segment;
        $this->pagination->initialize($config);
        $this->data['pagination'] = $this->pagination->create_links();
        $this->data['offset'] = $offset;
        
        $this->render($this->data);
    }
    function add_kriteria_form($offset = 0){
        $this->data['content'] = "kriteria/v_kriteria";
        $this->data['subLink'] = "kriteria/add_kriteria_proses";
        $this->data['formTitle'] = "Form Tambah Data Kriteria";
        $this->data['formView'] = "kriteria/addKriteriaForm";
        
        $uri_segment = 3;
        if($offset != 0){
          $offset = $this->uri->segment($uri_segment);  
        }
        $num_rows = $this->m_kriteria->getCountRows();
        $this->data['listKriteria'] = $this->m_kriteria->getListKriteria($offset,$this->limit);
        $config['base_url'] = site_url('kriteria/add_kriteria_form');
        $config['total_rows'] = $num_rows;
        $config['per_page'] = $this->limit;
        $config['uri_segment'] = $uri_segment;
        $this->pagination->initialize($config);
        $this->data['pagination'] = $this->pagination->create_links();
        $this->data['offset'] = $offset;
        
        $this->render($this->data);
    }
    function edit_kriteria_form($id,$offset = 0){
        $this->data['content'] = "kriteria/v_kriteria";
        $this->data['subLink'] = "kriteria/edit_kriteria_proses";
        $this->data['formTitle'] = "Form Edit Data Kriteria";
        $this->data['formView'] = "kriteria/editKriteriaForm";
        $this->data['dataInput'] = $this->m_kriteria->getKriteriaById($id);
        
        $uri_segment = 4;
        if($offset != 0){
          $offset = $this->uri->segment($uri_segment);  
        }
        $num_rows = $this->m_kriteria->getCountRows();
        $this->data['listKriteria'] = $this->m_kriteria->getListKriteria($offset,$this->limit);
        $config['base_url'] = site_url('kriteria/edit_kriteria_form/'.$id);
        $config['total_rows'] = $num_rows;
        $config['per_page'] = $this->limit;
        $config['uri_segment'] = $uri_segment;
        $this->pagination->initialize($config);
        $this->data['pagination'] = $this->pagination->create_links();
        $this->data['offset'] = $offset;
        
        $this->render($this->data);
    }
    function add_kriteria_proses(){
        $data = array('nama' => $this->input->post('nama'),
            'jenis' => $this->input->post('jenis'));
        $insert = $this->m_kriteria->addKriteria($data);
        if($insert == TRUE){
            $this->session->set_flashdata("message",1);
        }else{
            $this->session->set_flashdata("message",2);
        }
        
        redirect("kriteria");
    }
    function edit_kriteria_proses(){
        $data = array('id' => $this->input->post('id'),
            'nama' => $this->input->post('nama'),
            'jenis' => $this->input->post('jenis'));
        $update = $this->m_kriteria->editKriteria($data);
        if($update == TRUE){
            $this->session->set_flashdata("message",1);
        }else{
            $this->session->set_flashdata("message",2);
        }
        
        redirect("kriteria");
    }
    function delete_kriteria($id){
        $delete = $this->m_kriteria->deleteKriteria($id);
        if($delete == TRUE){
            $this->session->set_flashdata("message",3);
        }else{
            $this->session->set_flashdata("message",4);
        }
        
        redirect("kriteria");
    }
}
?>
